package com.suning.sawp.web.controller;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.vgs.follow.remote.intf.StoreManRemoteService;
import com.suning.vgs.follow.remote.store.WdWapImDto;

/**
 * 
 * 店+wap页注册功能<br>
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/registerP")
public class WapRegisterController {

    /**
     * 日志
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(WapRegisterController.class);

    /**
     * follow 保存用户发展用户信息接口
     */
    @Resource
    StoreManRemoteService storeManRemoteService;

    /**
     * 初始绑定页面
     * 
     * @param staffCode 员工工号
     * @param channel 进入页面的渠道
     * @return 初始绑定页面
     */
    @RequestMapping("/toFastBindIndex")
    public String toFastBindIndex(String staffCode, String channel, String targetUrl, ModelMap model) {
        LOGGER.info("toFastBindIndex enter,staffCode={},channel={},targetUrl={}",
                new Object[] { staffCode, channel, targetUrl });
        model.put("staffCode", staffCode);
        // dubbo
        if (StringUtils.isEmpty(targetUrl)) {
            if (StringUtils.isEmpty(staffCode)) {
                targetUrl = "http://m.suning.com";
            } else {
                // 获取店员微店地址
                WdWapImDto result = storeManRemoteService.getWdKeeperByStaffId(staffCode);

                // 店员没开店默认传客户端苏宁首页地址
                if (null != result) {
                    targetUrl = result.getWdUrl();
                } else {
                    targetUrl = "http://m.suning.com";
                }
            }
        }
        model.put("targetUrl", targetUrl);
        model.put("channel", channel);
        LOGGER.info("toFastBindIndex exit,staffCode={},channel={},targetUrl={}",
                new Object[] { staffCode, channel, targetUrl });
        return "fastBindIndex.ftl";
    }

}
